package com.springboot.mapper;

import java.math.BigDecimal;
import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import com.springboot.po.Orders;

@Mapper
public interface OrdersMapper {
	
	//主键不插入只是null，开启自增长列，匹配(封装对象的属性和表中的字段)
	@Options(useGeneratedKeys=true , keyProperty = "orderId" , keyColumn = "orderId")
	@Insert("insert into orders(userId , businessId , orderDate , orderTotal , daId , orderState ， originDaId) values(#{userId} , #{businessId} , #{orderDate} , #{orderTotal},#{daId}, 0 , #{daId})")
	public int saveOrders(Orders orders);
	
	//存在一对多和多对一（商家和明细）
	public Orders getOrdersById(Integer orderId);
	//存在一对多和多对一（商家和明细）
	public List<Orders> listOrdersByUserId(String userId);
	
	@Update("update orders set orderState = #{orderState} where orderId = #{orderId}")
	public int updateOrderState(Integer orderId, Integer orderState);
	
	@Update("update orders set orderTotal = #{orderTotal} where orderId = #{orderId}")
	public int setOrderTotal(Integer orderId , BigDecimal orderTotal);
}
